/**
 * @param {number[]} digits
 * @return {number[]}
 */

export var plusOne = function (digits) {
  const ans = new Array(digits.length).fill(0)
  let [curr, carry] = [digits.length - 1, 1]
  while (curr >= 0) {
    const sum = digits[curr] + carry
    ans[curr] = sum % 10
    carry = Math.floor(sum / 10)
    curr--
  }
  if (carry > 0) {
    ans.unshift(carry)
  }
  return ans
}

export var plusOne2 = function (digits) {
  // js最大有效整数为2^53-1，所以要用BigInt
  return String(BigInt(digits.join('')) + BigInt(1)).split('')
}
